<?php
require_once 'common.inc.php';
!in_array('2',$larr)&&adminmsg('你没有被赋予操作该项的权限！');

$matches=parse_url($_SERVER['HTTP_REFERER']);

if('show'==$action){
		$sum=0;
		$sql="select * from area order by btcid";
        $query=$dsdb->query($sql);
        while($btc=$dsdb->fetch_array($query))
        {
                $acslist[]=$btc;
				$sum+=1;
        }
		
		$filename="../push/log/updowntxt.php";
		$str = file_get_contents($filename);	
		$str = explode(',',$str);

	include_once MCC_ROOT.'/templates/msystem/acsstint.htm';

}elseif('set'==$action){
	$str=array(0,0,0,0);

	if('-1'==$statusup){
		$upvalue=average($up,$sum);
	}elseif('1'==$statusup){
		$up=1;
	}elseif('0'==$statusup){
		$up=0;
	}
	if('0'==$upvalue){
		$str[0]=0;
	}else{
		$str[0]=$statusup;
	}
	if(empty($up))
		{$str[1]=0;}
	else{$str[1]=$up;}	


	if('-1'==$statusdown){
		$downvalue=average($down,$sum);
	}elseif('1'==$statusdown){
		$down=1;
	}elseif('0'==$statusdown){
		$down=0;
	}
	if('0'==$downvalue){
		$str[2]=0;
	}else{
		$str[2]=$statusdown;
	}
	if(empty($down))
		{$str[3]=0;}
	else{$str[3]=$down;}	
	
	//$msg="input,output\n";
	$msg="$downvalue,$upvalue\n";
	
	$h1='124.161.63.232';
	$p1='23656';
	//if(!sendin($msg,$h1,$p1)){

		$str = implode(',',$str);
		$filename="../push/log/updowntxt.php";
		$fp=fopen($filename,'wb+');
		if($fp)
		{
			fwrite($fp,$str);
			fclose($fp);
		}
		adminmsg('设置流量成功',"acsstint.php?action=show");
	//}echo "success!";
	//else
		//echo "flog!";
	//adminmsg('设置流量失败',"acsstint.php?action=show");
}

/*****************************************************************************/

function average($value,$sum){
	if('0'==$value){
		$average=0;
		return $average;
	}elseif(empty($value)){	
		adminmsg('请输入流量值',"acsstint.php?action=show");
	}elseif($value<0){
		adminmsg('你输入了错误的值',"acsstint.php?action=show");
	}elseif($value>0){
		$average=intval($value/$sum);
		return $average;
	}
}

//发送协议函数
	function sendin($msg,$host,$port)
	{		
			$str="";
			$fp=fsockopen($host,$port,$errno,$errstr,1);
			if(!$fp)
			{
				 echo   'sorry!';
			}
			else
			{
				fwrite($fp,$msg);
			}
			/*while (!feof($fp)) 
			{
					$str.=fread($fp,100);
					//echo $str;
			}*/  		
		//return $str;
	}
?>
